/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agh.air.bpel2bpmn.comparator.impl;

import org.agh.air.bpel2bpmn.comparator.AbstractComparator;
import org.agh.air.bpel2bpmn.exception.PatternNotFoundException;
import org.w3c.dom.Node;

/**
 *
 * @author paletz
 */
public class OnMessageComparator extends AbstractComparator {

    /* 
     *  <onMessage partnerLink="" portType="" operation="" variable="">
            <invoke name="Task-13610" partnerLink="" portType="" operation=""
                    inputVariable="" outputVariable=""/>
        </onMessage>
     */
    @Override
    public String compare(Node node) throws PatternNotFoundException {

        if (node.getNodeName().equals(ON_MESSAGE)) {

            String str = "onMessage" + LTMP;
            for (int i = 0; i < node.getChildNodes().getLength(); i++) {

                if (getIChild(node, i).getNodeName().equals(INVOKE)) {

                    str = str + getNameAttribute(getIChild(node, i));
                } else {
                    str = str + getIChild(node, i).getNodeName();
                }

                if (i != node.getChildNodes().getLength() - 1) {
                    str = str + ".";
                }
            }
            return str + RTMP;
        }
        throw new PatternNotFoundException();
    }
}
